package com.supermarket.demo1.services;


import com.supermarket.demo1.mapper.UserMapper;
import com.supermarket.demo1.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service //把服务层交给Spring框架进行管理
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public User login(User user) {
        //若用户输入的为空，则不需要调用mapper层
        if(user.getUserCode() == null || user.getUserCode().equals("")
        || user.getUserPassword() == null || user.getUserPassword().equals("")){
            return null;
        }
        List<User> userByUser = userMapper.getUserByUser(user);
        //为0 匹配失败
        if(userByUser.size() == 0){
            return null;
        }
        return userByUser.get(0);
    }

    @Override
    public List<User> getALlUser() {
        List<User> userlist = userMapper.getAllUser();
        return userlist;
    }

    @Override
    public List<User> getUserByPageSize(int NO, int size) {
        return null;
    }

    @Override
    public int addUser(User user) {
        return 0;
    }

    @Override
    public int updateUser(User user) {
        return 0;
    }

    @Override
    public int deleteUser(int id) {
        int count = userMapper.deleteUser(id);
        return count;
    }
}
